{{- $_ := set . "Version" ( splitList "/" .Values.global.doc_version | last ) }}

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  annotations:
    "werf.io/replicas-on-creation": "1"
  labels:
    service: backend
spec:
  minReadySeconds: 5
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      service: backend
  template:
    metadata:
      labels:
        service: backend
    spec:
      imagePullSecrets:
        - name: deckhouse-registry-site
      priorityClassName: {{ pluck .Values.werf.env .Values.priorityClassName | first | default .Values.priorityClassName._default }}
      containers:
        - name: backend
          command: ["/app/server"]
          image: {{ index .Values.werf.image "web-backend" }}
          {{- include "resources" . | nindent 10 }}
          ports:
          - containerPort: 8080
            name: http
            protocol: TCP
          env:
          - name: VROUTER_DOMAIN_MAP
            value: {{ .Values.global.domain_map | quote }}
          {{- include "vrouter_envs" . | nindent 10 }}
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
          volumeMounts:
            - name: release-channels
              mountPath: /app/release-channels
      volumes:
        - name: release-channels
          configMap:
            name: release-channels-data
---
apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  clusterIP: None
  selector:
    service: backend
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: backend
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: backend
  updatePolicy:
    updateMode: "Auto"
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: backend
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      service: backend
